﻿using Localization.Resources.AbpUi;
using Joy.Erp.BasicArchives.Localization;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.AspNetCore.Components;
using Volo.Abp.AspNetCore.ExceptionHandling;
using Joy.Erp.BasicArchives.ExceptionHandling;

namespace Joy.Erp.BasicArchives;

[DependsOn(
    typeof(BasicArchivesApplicationContractsModule),
    typeof(AbpAspNetCoreMvcModule))]
public class BasicArchivesHttpApiModule : AbpModule
{
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        PreConfigure<IMvcBuilder>(mvcBuilder =>
        {
            mvcBuilder.AddApplicationPartIfNotExists(typeof(BasicArchivesHttpApiModule).Assembly);
        });
    }

    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        Configure<AbpLocalizationOptions>(options =>
        {
            options.Resources
                .Get<BasicArchivesResource>()
                .AddBaseTypes(typeof(AbpUiResource));
        });

        context.Services.Replace(ServiceDescriptor.Transient<IExceptionToErrorInfoConverter, BasicArchivesExceptionToErrorInfoConverter>());
    }
}
